package com.matt.service.courseV2.impl;

import com.matt.commons.exception.BusinessException;
import com.matt.commons.page.PagerQuery;
import com.matt.domain.courseV2.Fabulous;
import com.matt.domain.courseV2.Vendor;
import com.matt.foundation.model.ErrorCode;
import com.matt.repository.courseV2.VendorCourseRecordRepository;
import com.matt.repository.courseV2.VendorFabulousRepository;
import com.matt.service.courseV2.VendorFabulousService;
import com.matt.service.courseV2.VendorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class VendorFabulousServiceImpl implements VendorFabulousService {

    @Autowired
    private VendorFabulousRepository vendorFabulousRepository;

    @Override
    public void add(Fabulous fabulous) {
        Fabulous fabulous1 = vendorFabulousRepository.findByUserIdAndResId(fabulous.getUserId(),fabulous.getResId());
        if (Objects.isNull(fabulous1)){
            vendorFabulousRepository.save(fabulous);
        }else {
            vendorFabulousRepository.delete(fabulous1);
        }
    }

    @Override
    public List<Fabulous> resIdFindAll(String resId) {
        List<Fabulous> list = vendorFabulousRepository.findByResId(resId);
        return list;
    }
}
